import webpack from 'webpack';
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';

export default {
	entry: {
		app: ['./app/client/main.js']
	},
	resolve: {
    // root: path.join(__dirname, 'bower_components'),
    extensions: ['', '.js', '.vue', '.css', '.scss'],
    alias: {
      client: path.join(__dirname, '../app/client'),
      common: path.join(__dirname, '../app/client/common'),
      comp: path.join(__dirname, '../app/client/common/components'),
      utils: path.join(__dirname, '../app/client/utils'),
      framework: path.join(__dirname, '../app/client/modules/framework'),
    }
  },
  output: {
  	path: path.join(__dirname, '../build'),
    filename: '[name].js',
    publicPath: '/build/'
  },
  module: {
  	noParse: [
  		path.join(__dirname, '../node_modules', 'jquery'),
  		path.join(__dirname, '../node_modules', 'video.js/dist/video.js'),

  	],
  	loaders: [
  		{
        test: /\.js$/,
        loaders: ['babel'],
        include: [path.join(__dirname, '../app/client'), path.join(__dirname, 'config')],
        exclude: [path.join(__dirname, '../node_modules'), path.join(__dirname, '../app/client/vendor')]
      }, {
        test: /\.vue$/,
        loader: 'vue'
      }, {
        test: /\.html$/,
        loader: 'vue-html',
        include: path.join(__dirname, '../app/client')
  		}, {
        test: /\.json$/,
        loader: 'json'
      }, {
  			test: /\.css$/,
  			loader: 'style-loader!css-loader?modules&importLoaders=2&localIdentName=[local]!autoprefixer-loader',
  			include: path.join(__dirname, '../app/client'),
  			exclude: path.join(__dirname, '../app/client/common/style')
      }, {
  			test: /\.css/,
  			loader: 'style-loader!css-loader',
  			include: [path.join(__dirname, '../app/client/common/style'), path.join(__dirname, '../node_modules')],
  		}, {
        test: /\.(sass|scss)$/,
        loader: 'style-loader!css-loader?modules&importLoaders=2&localIdentName=[local]___[hash:base64:5]!autoprefixer-loader!sass-loader',
        include: path.join(__dirname, '../app/client'),
        exclude: [path.join(__dirname, '../app/client/common/style')]
      }, {
        test: /\.(sass|scss)$/,
        loader: 'style-loader!css-loader!sass-loader',
        include: [path.join(__dirname, '../app/client/common/style')]
      }, {
        test: /\.(png|jpg|jpeg|gif)$/,
        loader: 'url-loader?limit=8192&name=resource/img/[hash].[ext]'
      }, {
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: 'url-loader?limit=10000&name=resource/font/[hash].[ext]&minetype=application/font-woff'
      }, {
        test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: 'file-loader?name=resource/font/[hash].[ext]'
      }
  	]
  },
  plugins: [
	  new webpack.NoErrorsPlugin(),
	  new webpack.optimize.OccurenceOrderPlugin(),
  	new webpack.ProvidePlugin({
	    $: 'jquery',
	    jQuery: 'jquery',
	    Vue: 'vue',
	    config: path.join(__dirname, './config')
	  }),
	  function(){
	  	return this.plugin('done', stats => {
	  		console.log(stats.toString({
	  			colors: true,
	  			chunks: false
	  		}))
	  	})
	  }
  ],
  vue: {
  	postcss: [require('cssnext')()]
  }
}